;
(function() {
	var vueTap = {};
	vueTap.install = function(Vue) {
		Vue.directive('tap', {
			acceptStatement: true,
			bind: function() {},
			update: function() {
			},
			inserted: function(el, binding) {
				var startX = 0;
				var endX = 0;
				var startY = 0;
				var endY = 0;
				//获取参数
				var fnObj = binding.value;
				el.addEventListener('touchstart', function(e) {
					var touch = e.changedTouches;
					startX = touch[0].clientX; //不带px
					startY = touch[0].clientY;
				}, false);
				el.addEventListener('touchend', function(e) {
					var touch = e.changedTouches;
					endX = touch[0].clientX;
					endY = touch[0].clientY;
					var moveDistanceX = startX - endX;
					var moveDistanceY = startY - endY;
					if(moveDistanceX > 50) {
						if(fnObj.leftFn){
							fnObj.leftFn();
						}
					} else if(moveDistanceX < -50) {
						if(fnObj.rightFn){
							fnObj.rightFn();
						}
					}
					if(moveDistanceY>50){
						if(fnObj.upFn){
							fnObj.upFn();
						}
					}else if(moveDistanceY<-50){
						if(fnObj.downFn){
							fnObj.downFn();
						}
					}
				}, false)
			},
			unbind: function() {

			}
		});
	}
	module.exports = vueTap;
})();